package com.asurplus.timer.task;

import com.asurplus.weixin.utils.WeiXinUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

/**
 * 项目启动任务--获取微信access_token
 *
 * @Author Lizhou
 **/
@Slf4j
@Component
public class WeiXinAccessTokenTask implements CommandLineRunner {

    @Autowired
    private WeiXinUtils weiXinUtils;

    @Value("${spring.profiles.active}")
    public String profiles;

    @Override
    public void run(String... args) throws Exception {
        // 如果是开发环境，就不需要执行
        if ("dev".equals(profiles)) {
            return;
        }
        weiXinUtils.getAccessToken();
    }
}
